package edu.uoc.tds.cliente;

import java.rmi.RemoteException;

import javax.swing.JOptionPane;

import edu.uoc.tds.bean.Evento;
import edu.uoc.tds.common.RemotoInterface;
import edu.uoc.tds.common.UtilLenguaje;
import edu.uoc.tds.common.Utils;

public class PantallaAsistentesEvento extends javax.swing.JPanel {
	private static final long serialVersionUID = 3508864662580563845L;
	private RemotoInterface objServeis;
	private Integer idEvento;
	private boolean existenAsistentes = false;

	public boolean existenAsistentes() {
		return existenAsistentes;
	}

	public void setExistenAsistentes(boolean existenAsistentes) {
		this.existenAsistentes = existenAsistentes;
	}

	/** Creates new form PantallaAsistentesEvento */
    public PantallaAsistentesEvento(RemotoInterface objServeis, Integer idEvento) {
    	super();
    	this.objServeis = objServeis;
    	this.idEvento = idEvento;
        initComponents();
    }

    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        botonVolver = new javax.swing.JButton();
       
        jLabel1.setText(UtilLenguaje.getMessage("pantAsistentesEventos.nombre.evento"));
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel3.setText(UtilLenguaje.getMessage("pantAsistentesEventos.fecha.evento"));
        jLabel3.setName("jLabel2"); // NOI18N

        jLabel2.setText("");
        jLabel2.setName("jLabel3"); // NOI18N

        jLabel4.setText("");
        jLabel4.setName("jLabel4"); // NOI18N
        
        try {
			Evento evento = objServeis.getEvento(idEvento);
			jLabel2.setText(evento.getNombre());
			jLabel4.setText(Utils.convertirFecha(evento.getFechaInicio()));
		} catch (RemoteException re) {
			Utils.tratarRemoteException(re);
		}

        jLabel5.setText(UtilLenguaje.getMessage("pantAsistentesEventos.inscripciones.evento"));
        jLabel5.setName("jLabel5"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(null,
                new String [] {
                    UtilLenguaje.getMessage("pantAsistentesEventos.head.codigo"), 
                    UtilLenguaje.getMessage("pantAsistentesEventos.head.nombre"), 
                    UtilLenguaje.getMessage("pantAsistentesEventos.head.apellidos"), 
                    UtilLenguaje.getMessage("pantAsistentesEventos.head.inscripcion")
                }
            ));
        try {
			Object[][] asistentesEvento = objServeis.getAsistentesEvento(idEvento);
	        jTable1.setModel(new javax.swing.table.DefaultTableModel(asistentesEvento,
	                new String [] {
	                    UtilLenguaje.getMessage("pantAsistentesEventos.head.codigo"), 
	                    UtilLenguaje.getMessage("pantAsistentesEventos.head.nombre"), 
	                    UtilLenguaje.getMessage("pantAsistentesEventos.head.apellidos"), 
	                    UtilLenguaje.getMessage("pantAsistentesEventos.head.inscripcion")
	                }
	            ));
	        if (asistentesEvento == null) {
                JOptionPane.showMessageDialog(null, UtilLenguaje.getMessage("pantAsistentesEventos.buscar.sinresultado.desc"),
                		UtilLenguaje.getMessage("pantAsistentesEventos.buscar.titulo"), JOptionPane.INFORMATION_MESSAGE);
	        } else {
	        	existenAsistentes = true;
	        }
		} catch (RemoteException re) {
			Utils.tratarRemoteException(re);
		}
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        botonVolver.setText(UtilLenguaje.getMessage("pantAsistentesEventos.boton.volver"));
        botonVolver.setName("jButton1"); // NOI18N
        botonVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	jVolverActionPerformed(evt);
            }
        });


        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel1)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addComponent(jLabel2)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 152, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLabel3)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(10, 10, 10)
                                    .addComponent(jLabel4)))
                            .addContainerGap(150, Short.MAX_VALUE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel5)
                            .addContainerGap(356, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(156, 156, 156)
                        .addComponent(botonVolver)
                        .addContainerGap(171, Short.MAX_VALUE))
       );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addGap(28, 28, 28)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addComponent(botonVolver))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jVolverActionPerformed(java.awt.event.ActionEvent evt) {
    	PantallaCalendarioEventos pantallaCalendarioEventos = (PantallaCalendarioEventos) this.getParent().getComponent(0);
    	this.setVisible(false);
    	this.getParent().remove(1);
    	pantallaCalendarioEventos.setVisible(true);    	
    }
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonVolver;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

}
